package cn.edu.cdtu.yulei.test_demo.controller;

import cn.edu.cdtu.yulei.test_demo.utils.FileDownloader;
import com.google.gson.Gson;

import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/fileService/down.do")
public class DownloadController extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        FileDownloader.download(req.getParameter("fileUrl"));
        ServletOutputStream outputStream = resp.getOutputStream();
        Gson gson = new Gson();
        String fileAddress = "http://47.113.184.61:8080/";
        outputStream.write(gson.toJson(fileAddress).getBytes("utf-8"));
        outputStream.close();
    }
}
